package com.hentie.mathlib;

public class Vector2 {
	
	//The x,y,z representation
	float[] xy = new float[2];
	
	public Vector2(float x,float y)
	{
		xy[0]=x;
		xy[1]=y;
	}
	
	public Vector2(Vector2 copy)
	{
		xy[0] = copy.xy[0];
		xy[1]= copy.xy [1];
	}
	
	public static Vector2 One()
	{
		return new Vector2(1,1);
	}
	public static Vector2 Zero()
	{
		return new Vector2(0,0);
	}
	
	
	public float length()
	{
		return (float)Math.sqrt(lengthSquared());
		
	}
	
	public float lengthSquared()
	{
		return xy[0]*xy[0] + xy[1]*xy[1];
	}
	
	public void normalize()
	{
		float length = length();
		
		xy[0]/=length;
		xy[1]/=length;
	}
	
	public float X()
	{
		return xy[0];
	}

	public float Y()
	{
		return xy[1];
	}
	
	public static float dot(Vector2 first,Vector2 second)
	{
		return first.xy[0]*second.xy[0]+first.xy[1]*second.xy[1];
	}

	public void Set(float x, float y)
	{
		xy[0]=x;
		xy[1]=y;
	}
	
	@Override
	public String toString()
	{
		return new String("X: "+String.valueOf(xy[0]) +" Y: "+String.valueOf(xy[1]) );
		
	}

}
